package com.kangkang.shixi;

import java.util.ArrayList;
import java.util.List;

public class Student implements Comparable<Student> {
    private int id;
    private String name;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public char getSex() {
        return sex;
    }

    public void setSex(char sex) {
        this.sex = sex;
    }

    public String getClsName() {
        return clsName;
    }

    public void setClsName(String clsName) {
        this.clsName = clsName;
    }

    public List<Float> getScores() {
        return scores;
    }

    public void setScores(List<Float> scores) {
        this.scores = scores;
    }

    private char sex;
    private String clsName;
    private List<Float> scores;

    public Student(int id, String name, char sex, String cls) {
        this.id = id;
        this.name = name;
        this.sex = sex;
        this.clsName = cls;
        scores = new ArrayList<>();
    }

    public float getMaxScore() {
        float max = 0;
        for (Float score : scores) {
            max = Math.max(score, max);
        }
        return max;
    }

    public void addScore(float score) {
        scores.add(score);
    }

    public float getAvgScore() {
        if (scores.size() == 0) {
            return 0.0f;
        }
        float avg = 0.0f;
        for (Float score : scores) {
            avg += score;
        }
        return avg / scores.size();
    }

    @Override
    public String toString() {
        return "Student{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", sex=" + sex +
                ", clsName='" + clsName + '\'' +
                ", scores=" + scores +
                '}';
    }

    public float getSumScore(){
        float sum = 0.0f;
        for (Float score : scores) {
            sum += score;
        }
        return sum;
    }
    @Override
    public int compareTo(Student o) {
        if(this.getSumScore() != o.getSumScore()){
            if(this.getSumScore() < o.getSumScore()) return 1;
        } else if(this.id != o.id){
            if(this.id < o.id) return 1;
        }
        return -1;
    }
}
